func shipWithinDays(weights []int, days int) int {
	left, right := 0, 0
	for _, w := range weights {
		left = max(left, w)
		right += w
	}
	for left < right {
		mid := left + (right-left)/2
		sum, day := 0, 1
		for _, w := range weights {
			if sum+w > mid {
				sum = 0
				day++
			}
			sum += w
		} //遍历weights数组，O(n)
		if day <= days {
			right = mid
		} else {
			left = mid + 1
		}
	} //二分查找O(log(Sum)),Sum为weight数组总和
	//因此总的复杂度为O(n*logSum)
	return left
}
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}
